package com.karaoke.android.kege.widget

import android.content.Context
import android.util.AttributeSet
import android.util.TypedValue
import android.widget.FrameLayout
import com.joanzapata.iconify.widget.IconTextView
import com.karaoke.android.data.domain.DataDictionary
import com.karaoke.android.kege.R


/**
 * Created by allen on 2017/4/22.
 */

class MenuItem @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(
        context,
        attrs,
        defStyleAttr)
{

    //    private val title: TextView
    private val icon: IconTextView
    // private var drawable: IconDrawable? = null
    //private var checkedDrawable: Drawable? = null

    var item: DataDictionary? = null
        set(value)
        {
            field = value
//            title.text = field?.name
            icon.text = "${field?.image ?: ""}  ${field?.name}"
            //drawable = IconDrawable(context,KegeIcons.category_liu_xing).sizeDp(30).actionBarSize()
            // checkedDrawable = PrintDrawable.Builder(context).iconText(item?.image).iconSizeDp(30f).iconColorRes(R.color.category_text_cheched).build()
        }

    init
    {
        inflate(context, R.layout.menu_item, this)
//        title = findViewById(R.id.title) as TextView
        icon = findViewById(R.id.icon) as IconTextView
    }


    override fun setActivated(activated: Boolean)
    {
        super.setActivated(activated)
        if (!activated)
        {
//            title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
            icon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
            //icon.setImageDrawable(drawable)
            setBackgroundResource(R.color.transparent)
        }
        else
        {
//            title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f)
            icon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f)
            //icon.setImageDrawable(checkedDrawable)
            setBackgroundResource(R.drawable.menu_shape)
        }
    }

}
